#!/bin/sh
#
# This is a tomcat init.d script which is called by init(1) with [start|stop] as argument
#

ARGS="-classpath /usr/tomcat/bin/bootstrap.jar -Dcatalina.home=/usr/tomcat org.apache.catalina.startup.Bootstrap"

for j in /usr/bin/jamvm /usr/bin/java $JAVA_HOME/bin/java; do
	if [ -x "$j" ]; then
		JAVA="$j"
		break
	fi
done

if [ -z "$JAVA" ]; then
	echo java not found.
	exit 1
fi

start_proc(){
	mkdir -p /tmp/tomcat/temp
	mkdir -p /tmp/tomcat/work
	mkdir -p /tmp/tomcat/logs

	$JAVA $ARGS start > /dev/null 2>&1 &
}

stop_proc(){
	$JAVA $ARGS stop
}


case "$1" in
	start)
		start_proc
		;;
	stop)
		stop_proc
		;;
	restart)
		stop_proc
		start_proc
		;;
	*)
		echo "Usage: $0 {start|stop|restart}"
		echo ""
		exit 1
		;;
esac

exit 0

